#include "widget.h"
#include "ui_widget.h"
#include <QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->listWidget->addItem(new QListWidgetItem("C++"));
    ui->listWidget->addItem(new QListWidgetItem("java"));
    ui->listWidget->addItem(new QListWidgetItem("py"));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    int row = ui->listWidget->currentRow();
    if(row < 0)return;
    ui->listWidget->takeItem(row);
}

void Widget::on_pushButton_2_clicked()
{
    const QString& newItem = ui->lineEdit->text();
    if(newItem.size()>0)ui->listWidget->addItem(newItem);
    ui->lineEdit->setText("");
}

void Widget::on_listWidget_currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
{
    if(current)
    {
        qDebug() << current->text();
    }
    if(previous)qDebug() << previous->text();
}
